package com.itzmn.java.javase.io.bio;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author: 张梦楠
 * @Date: 2018/12/26 15:40
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description:
 */
public class BIOClient1 {

    public static void main(String[] args) {
        OutputStream outputStream = null;
        try {
            int i= 0,j=1;
            Socket socket = new Socket("localhost", 8080);
            Scanner scanner = new Scanner(System.in);
            outputStream = socket.getOutputStream();
            System.out.println("请输入内容:");
            String s = scanner.nextLine();
            outputStream.write((""+s).getBytes());
            outputStream.flush();
            System.out.println("客户端已发送:"+s);
        } catch (IOException e) {
            System.out.println("客户端启动失败");
            e.printStackTrace();
        }finally {
            try {
                if (outputStream != null){
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
